def weimar(x):
    for d in range(2,x//2+1):
        if x%d==0:
            return 0
    return 1
a=str(input())
r=[0]
if len(a)!=4:
    print('0')
    exit()
for i in range(len(a)-2):
  if weimar(int(a[i]+a[i+1]+a[i+2]))==1:
     r.append(int(a[i]+a[i+1]+a[i+2]))
for i in range(len(a)-1):
  if weimar(int(a[i]+a[i+1]))==1:
     r.append(int(a[i]+a[i+1]))
for i in range(len(a)):
  if weimar(int(a[i]))==1:
     r.append(int(a[i]))
if weimar(int(a))==1:
    r.append(int(a))
print(max(r))
